package com.easy.dfcapi.web;

import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.common.util.IPUtil;
import com.easy.core.web.Api20Controller;
import com.easy.dfcapi.res.BuyerUserRes;
import com.easy.dfcapi.res.Response;
import com.easy.dfcapi.service.ApiFollowService;
import com.easy.dfcapi.service.ApiUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户相关控制器
 */

@Controller
@RequestMapping(value = "${apiPath}/2.0/follow")
public class ApiFollowController extends Api20Controller {


    @Autowired
    private ApiUserService userService;

    @Autowired
    private ApiFollowService followService;

    /**
     * 我的风车-收藏&关注&足迹统计
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FollowInfo", method = RequestMethod.POST)
    public Result FollowInfo(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.FollowInfo(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-收藏列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FavoriteProduct", method = RequestMethod.POST)
    public Result FavoriteProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.FavoriteProduct(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-关注列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FollowProduct", method = RequestMethod.POST)
    public Result FollowProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.FollowProduct(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-产品足迹列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FootStepProduct", method = RequestMethod.POST)
    public Result FootStepProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.FootStepProduct(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-收藏列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FavoriteStore", method = RequestMethod.POST)
    public Result FavoriteStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.FavoriteStore(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-关注列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FollowStore", method = RequestMethod.POST)
    public Result FollowStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.FollowStore(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-产品足迹列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FootStepStore", method = RequestMethod.POST)
    public Result FootStepStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.FootStepStore(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 增加店铺收藏
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFavoriteStore", method = RequestMethod.POST)
    public Result AddFavoriteStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.AddFavorite(response,1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 增加宝贝收藏
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFavoriteProduct", method = RequestMethod.POST)
    public Result AddFavoriteProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.AddFavorite(response,2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 增加店铺关注
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFollowStore", method = RequestMethod.POST)
    public Result AddFollowStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));

            return followService.AddFollow(response,1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 增加宝贝关注
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFollowProduct", method = RequestMethod.POST)
    public Result AddFollowProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.AddFollow(response,2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 增加店铺足迹
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFootStepStore", method = RequestMethod.POST)
    public Result AddFootStepStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.AddFootStep(response,1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 增加宝贝足迹
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "AddFootStepProduct", method = RequestMethod.POST)
    public Result AddFootStepProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.AddFootStep(response,2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 判断店铺是否收藏
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HaveFavoriteStore", method = RequestMethod.POST)
    public Result HaveFavoriteStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.HaveFavorite(response,1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 判断宝贝是否收藏
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HaveFavoriteProduct", method = RequestMethod.POST)
    public Result HaveFavoriteProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.HaveFavorite(response,2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 判断店铺是否关注
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HaveFollowStore", method = RequestMethod.POST)
    public Result HaveFollowStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.HaveFollow(response,1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 判断宝贝是否关注
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "HaveFollowProduct", method = RequestMethod.POST)
    public Result HaveFollowProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.HaveFollow(response,2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }


    /**
     * 删除店铺收藏
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFavoriteStore", method = RequestMethod.POST)
    public Result DelFavoriteStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.DelFavorite(response,1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 删除宝贝收藏
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFavoriteProduct", method = RequestMethod.POST)
    public Result DelFavoriteProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.DelFavorite(response,2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 删除店铺关注
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFollowStore", method = RequestMethod.POST)
    public Result DelFollowStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.DelFollow(response,1);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 删除宝贝关注
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFollowProduct", method = RequestMethod.POST)
    public Result DelFollowProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.DelFollow(response,2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

    /**
     * 删除店铺足迹
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFootStepStore", method = RequestMethod.POST)
    public Result DelFootStepStore(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.DelFootStep(response,1);
        } catch (Exception e) {
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 删除宝贝足迹
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "DelFootStepProduct", method = RequestMethod.POST)
    public Result DelFootStepProduct(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.DelFootStep(response,2);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }


    /**
     * 我的风车-收藏列表OLD
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FavoriteProductOld", method = RequestMethod.POST)
    public Result FavoriteProductOld(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.FavoriteProductOld(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }
    /**
     * 我的风车-关注列表
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "FollowStoreOld", method = RequestMethod.POST)
    public Result FollowStoreOld(Response<BuyerUserRes> response, HttpServletRequest request) {
        try {
            if(!response.isValidator()){
                return response.getResult();
            }
            response.setIp(IPUtil.getIpAddress(request));
            return followService.FollowStoreOld(response);
        } catch (Exception e) {
            logger.error(e.toString());
            Result rt = new Result();
            rt.setStatus(EnumConfig.S_CODE.DB_ERROR);
            return rt;
        }
    }

}
